package com.ux.iot.jetlinks.util;

import cn.hutool.core.codec.Base64;
import com.ux.iot.jetlinks.service.sub.request.ServiceInfo;

import java.util.UUID;

/**
 * @author caixiaodao
 * @version 1.0
 * 功能描述
 * 工具类
 * @date 2021/11/15 11:06
 */
public class JetlinksUtil {
    /**
     * 生成 订阅requestId
     * @param serviceInfo
     * @param topic
     * @param productId
     * @param deviceId
     * @return
     */
    public static String bulidSubRequestId(ServiceInfo serviceInfo, String topic, String productId, String deviceId){
        String s=serviceInfo.getAppName().concat("-").concat(serviceInfo.getPort()).concat(Base64.encode(topic)).concat("-").concat(productId).concat("-").concat(deviceId);
        return  s;

    }

    /**
     * 订阅 requestId 解码器
     * @return
     */
    public static  String subRequestIdDecode(String requestId){
        return  Base64.decodeStr(requestId);
    }
    /**
     * 生成消息的requestId
     */
    public static String requestId(){
       return UUID.randomUUID().toString();
    }
}
